use std::error::Error;

pub type LitResult<T> = Result<T,LitError>;

#[derive(Debug)]
pub enum LitError {
    Byte(crate::byte::ByteError),
    Huffman(crate::huffman::HuffmanError),
    HuffmanTableMissing,
}

impl std::fmt::Display for LitError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Byte(e) => write!(f,"[lit]{e}"),
            Self::Huffman(e) => write!(f,"[lit]{e}"),
            Self::HuffmanTableMissing => write!(f,"[lit]huffman table missing"),
        }
    }
}

impl Error for LitError { }

impl From<crate::byte::ByteError> for LitError {
    fn from(value: crate::byte::ByteError) -> Self {
        Self::Byte(value)
    }
}

impl From<crate::huffman::HuffmanError> for LitError {
    fn from(value: crate::huffman::HuffmanError) -> Self {
        Self::Huffman(value)
    }
}